package com.example.fragmentdemo.player;

import androidx.appcompat.app.AppCompatActivity;

import android.annotation.SuppressLint;
import android.media.MediaPlayer;
import android.net.Uri;
import android.os.Bundle;
import android.view.animation.Animation;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.MediaController;
import android.widget.SeekBar;
import android.widget.TextView;
import android.widget.VideoView;

import com.example.fragmentdemo.R;

import java.io.File;

public class VideoPlayerActivity extends AppCompatActivity {
    private VideoView videoView;
    private MediaPlayer mediaPlayer;
    private Uri fileUri;
    private String videoUrl;
    private TextView title;



    @SuppressLint("MissingInflatedId")
    @Override
    protected void onCreate(Bundle savedInstanceState) {



        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_media_player);

        videoView = findViewById(R.id.video_view);
        title=findViewById(R.id.title);

        // 获取从其他Activity传递过来的Intent
        videoUrl = getIntent().getStringExtra("uri");
        title.setText(getIntent().getStringExtra("name"));


        assert videoUrl != null;
        Uri videoUri = Uri.fromFile(new File(videoUrl));
        videoView.setVideoPath(String.valueOf(videoUri));
        videoView.setMediaController(new MediaController(this));
        videoView.setOnPreparedListener(new MediaPlayer.OnPreparedListener() {
            @Override
            public void onPrepared(MediaPlayer mediaPlayer) {
                mediaPlayer.seekTo(1000);
                mediaPlayer.isPlaying();
            }
        });
    }




    @Override
    protected void onDestroy() {
        super.onDestroy();
        if (mediaPlayer != null) {
            mediaPlayer.release();
            mediaPlayer = null;
        }
    }
}